<%@ page import="com.jbit.examSystem.pojo.Question" %>
<%@ page import="java.util.List" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<%@include file="../../common/include-header.jsp" %>
<body>
<div class="form-content">
    <form id="form-exam-add" class="form-horizontal">
        <h4 class="form-header h4">基本信息</h4>
        <div class="row">
            <div class="col-sm-6">
                <div class="form-group">
                    <input type="hidden" name="testPaperId" value="${testPaper.id}"/>
                    <label class="col-sm-4 control-label"><span style="color: red; ">*</span>试卷名：</label>
                    <div class="col-sm-8">
                        <input name="name" autocomplete="off" placeholder="请输入试卷题目" class="form-control" type="text"
                               value="${testPaper.name}"
                               required
                               maxlength="30" required>
                    </div>
                </div>
            </div>

            <div class="col-sm-6">
                <div class="form-group">
                    <label class="col-sm-4 control-label"><span style="color: red; ">*</span>题目数量：</label>
                    <div class="col-sm-8">
                        <input name="amount" autocomplete="off" class="form-control" type="number"
                               value="${testPaper.amount}"
                               maxlength="50"
                               placeholder="题目数量" required>
                    </div>
                </div>
            </div>
        </div>
        <div class="row">
            <div class="col-sm-6">
                <div class="form-group">
                    <label class="col-sm-4 control-label"><span style="color: red; ">*</span>持续时间：</label>
                    <div class="col-sm-8">
                        <input name="duration" autocomplete="off" class="form-control" type="number"
                               value="${testPaper.duration}"
                               maxlength="50"
                               placeholder="请输入持续时间" required>
                    </div>
                </div>
            </div>
        </div>
        <div class="row">
            <div class="col-sm-12">
                <div class="form-group">
                    <label class="col-xs-2 control-label"><span style="color: red; ">*</span>试卷科目：</label>
                    <div class="col-xs-4">
                        <select class="form-control select2-hidden-accessible subid" required name="courseId"
                                disabled="disabled">
                            <c:forEach items="${courses}" var="sList">
                                <c:if test="${sList.id==testPaper.courseId}">
                                    <option value="${sList.id}" selected>${sList.name}</option>
                                </c:if>
                            </c:forEach>
                        </select>
                    </div>
                </div>
            </div>
        </div>
        <%--<div class="row">
            <div class="col-sm-12">
                <div class="form-group">
                    <label class="col-xs-2 control-label">指定阅卷老师：</label>
                    <div class="col-xs-4">
                        <select class="form-control select2-hidden-accessible" required name="reviewerId">
                            <option>请选择</option>
                            <c:forEach items="${trachers}" var="teacher">
                                <c:if test="${teacher.id==exam.reviewerId}">
                                    <option value="${teacher.id}" selected>${teacher.nickName}</option>
                                </c:if>
                                <c:if test="${teacher.id==exam.reviewerId}">
                                    <option value="${teacher.id}">${teacher.nickName}</option>
                                </c:if>
                            </c:forEach>
                        </select>
                    </div>
                </div>
            </div>
        </div>--%>

        <%--<div class="row">
            <div class="col-sm-12">
                <div class="form-group">
                    <label class="col-xs-2 control-label">指定参考学生：</label>
                    <div class="col-xs-4">
                        <select id="studentIds" class="form-control select2-hidden-accessible" multiple="">
                            <c:forEach items="${students}" var="student">
                                <c:if test="${student.studentCheckFlag}">
                                    <option value="${student.id}" selected>${student.nickName}</option>
                                </c:if>
                                <c:if test="${!student.studentCheckFlag}">
                                    <option value="${student.id}">${student.nickName}</option>
                                </c:if>
                            </c:forEach>
                        </select>
                    </div>
                </div>
            </div>
        </div>--%>

    </form>
    <h4 class="form-header h4">指定试卷的题目</h4>
    <div class="row">
        <div class="col-sm-12  ">
            <table id="bootstrap-table1" data-mobile-responsive="true"></table>
        </div>
    </div>
    <div class="container-div">
        <div class="row">
            <%--<div class="col-sm-12 search-collapse">
                <form id="role-form">
                    <div class="select-list">
                        <ul>
                            <li>
                                年级：
                                <select name="gradeId" id="gradeId" style="width: 130px" >
                                    <option value="">请选择</option>
                                    <c:forEach items="${grades}" var="grade">
                                        <option value="${grade.id}">${grade.name}</option>
                                    </c:forEach>
                                </select>
                            </li>
                            <li>
                                课程：
                                <select name="courseId" id="courseId" style="width: 170px" >
                                    <option value="">请选择</option>
                                </select>
                            </li>
                            <li>
                                章节：
                                <select name="chapterId" id="chapterId" style="width: 170px" disabled>
                                    <option value="">请选择</option>
                                </select>
                            </li>
                            <li>
                                试题名称：<input type="text" name="question" style="width: 170px"/>
                            </li>
                            <li>
                               试题类型：<input type="text" name="type" style="width: 170px"/>
                                试题类型：
                                <select name="typeId">
                                    <option value="">请选择</option>
                                    <option value="10000">单选</option>
                                    <option value="10001">多选</option>
                                </select>
                            </li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i
                                        class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i
                                        class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-success" onclick="$.operate.add()">
                    <i class="fa fa-plus"></i> 添加试题
                </a>
                <span class="text-info"> 请直接选择需要添加的试题</span>
            </div>--%>

            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table" data-mobile-responsive="true"></table>
            </div>
        </div>
    </div>
    <%@include file="../../common/include-footer.jsp" %>
    <input type="hidden" id="checkedQuestion" value="${exam.idsStr}"/>
    <script>
        $(function () {
            /*var servicesArray = data.split(",");
            $("input[type=checkbox][name=btSelectItem]").each(function (i, e) {
                for (var i = 0; i < servicesArray.length; i++) {
                    if ($(this).val() == servicesArray[i]) {
                        $(this).iCheck('check');
                    }
                }
            });*/

            setTimeout(function () {
                var $text = $('input[name=btSelectItem]').parent().eq(9).next().text();
                alert($text)
            }, 1000)

        });

        var data = $("#checkedQuestion").val();
        var prefix = "${pageContext.request.contextPath}/question";
        $(function () {
            $('#gradeId').change(function () {
                var gradeId = $(this).val();
                if (gradeId != null) {
                    $.ajax({
                        url: "${pageContext.request.contextPath}/course/list",    //请求的url地址
                        dataType: "json",   //返回格式为json
                        data: {"gradeId": gradeId},    //参数值
                        type: "POST",   //请求方式
                        success: function (data) {
                            $('.hz1').remove();
                            var courses = data;
                            for (var i = 0; i < courses.length; i++) {
                                var name = courses[i].name;
                                var id = courses[i].id;
                                //给下拉框动态赋值
                                $("select[name=courseId]").append("<option class='hz1' value='" + id + "'>" + name + "</option>");
                            }
                        }
                    });
                    $('select[name=chapterId]').attr("disabled", true);
                }
            });
            $('#courseId').change(function () {
                var courseId = $(this).val();
                if (courseId != null) {
                    $.ajax({
                        url: "${pageContext.request.contextPath}/question/getChapterByCourseId",    //请求的url地址
                        dataType: "json",   //返回格式为json
                        data: {"courseId": courseId},    //参数值
                        type: "POST",   //请求方式
                        success: function (data) {
                            var chapters = data;
                            $('.hz2').remove();
                            for (var i = 0; i < chapters.length; i++) {
                                var name = chapters[i].name;
                                var id = chapters[i].id;
                                //给下拉框动态赋值
                                $("select[name=chapterId]").append("<option class='hz2' value='" + id + "'>" + name + "</option>");
                            }
                            // alert($("#subid").val());
                        }
                    });
                    $('select[name=chapterId]').attr("disabled", false);
                }
            });

            var options = {
                url: prefix + "/list",
                removeUrl: prefix,
                sortName: "",
                sortOrder: "desc",
                escape: true,
                modalName: "试题",
                clickToSelect: true,
                rememberSelected: true,
                columns: [{
                    field: 'state',
                    checkbox: true,
                    formatter: function (value, item, index) {
                        var temp = data.split(",");
                        for (var i = 0; i < temp.length; i++) {
                            if (temp[i] == item.id) {
                                return {
                                    checked: true//设置选中
                                };
                            }
                        }
                        return {
                            checked: false//设置选中
                        };
                    }
                },
                    {
                        field: 'id',
                        title: '试题ID'
                    },
                    {
                        field: 'gradeName',
                        title: '年级'
                    },
                    {
                        field: 'courseName',
                        title: '课程',
                    },
                    {
                        field: 'chapterName',
                        title: '章节',
                    },
                    {
                        field: 'question',
                        title: '试题的标题',
                        sortable: true
                    },
                    {
                        field: 'typeId',
                        title: '试题类型',
                        formatter: function (value, item, index) {
                            if (item.typeId == '10000') {
                                return '<span class="label label-success">单选</span>';
                            } else if (item.typeId == '10001') {
                                return '<span class="label label-primary">多选</span>';
                            }
                        }
                    }]
            };
            $.table.init(options);
        });

        function submitHandler() {
            var data = $("#form-exam-add").serialize();
            $.operate.savePut("/testPaper/update", data);

        }
    </script>

</div>

<%@include file="../../common/include-footer.jsp" %>

<script src="/static/plugin/select/select2.js"></script>

</body>
</html>
